		TITLE	RECOHNDL - Copyright (C) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	LIBRARY
		INCLUDE	WIN32DEF

		PUBLIC	RECOVER_HANDLE


		.DATA

		EXTERNDEF	LAST_LIB_GINDEX:DWORD,CURN_LIBNUM:DWORD,CURNLIB_GINDEX:DWORD

		EXTERNDEF	LIBRARY_GARRAY:STD_PTR_S


		.CODE	PASS1_TEXT

		EXTERNDEF	_close_handle:proc


RECOVER_HANDLE	PROC
		;
		;DID WE FAIL FROM LACK OF HANDLES?
		;
		CALL	GetLastError

		CMP	EAX,4			;OUT OF HANDLES?
		JNZ	L9$			;NO, DIFFERENT ERROR, ABORT

		BITT	HANDLES_EXPANDED
		JNZ	L05$

		SETT	HANDLES_EXPANDED

		PUSH	255
		CALL	SetHandleCount

		CMP	AL,AL

		RET

L05$:
		MOV	EAX,LAST_LIB_GINDEX
		MOV	EDX,CURNLIB_GINDEX

		TEST	EAX,EAX			;ANY LIBS?
		JZ	L9$			;NO, ABORT
L1$:
		CONVERT	ECX,EAX,LIBRARY_GARRAY
		ASSUME	ECX:PTR LIBRARY_STRUCT

		CMP	EAX,EDX
		JZ	L3$			;SKIP ME

		MOV	EAX,[ECX]._LS_HANDLE

		TEST	EAX,EAX
		JNZ	L5$			;CLOSE IF OPEN
L3$:
		MOV	EAX,[ECX]._LS_PREV_LIB_GINDEX	;MORE LIBS?

		TEST	EAX,EAX
		JNZ	L1$			;YES, JUMP
L9$:
		OR	AL,-1
		CMP	ESP,-1

		RET

L5$:
		MOV	[ECX]._LS_HANDLE,0

		push	EAX
		call	_close_handle
		add	ESP,4

		CMP	AL,AL

		RET

RECOVER_HANDLE	ENDP


		END

